# !python3      # 使用工具:PyCharm
# 用户登录名:yyds_l
# 项目名称: python爬虫     文件名称:封装查找元素1
# 系统日期:2022/3/15      系统时间:1:01
# 2022/03/15 01:01

"""ok"""
import requests
from bs4 import BeautifulSoup

dome = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title" name="dromouse"><b>The Dormouse's story</b></p>
<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1"><!-- Elsie --></a>,
<a href="http://example.com/elsie" class="sister" id="link2"><!-- Elsie --></a>,
<a href="http://example.com/elsie" class="sister" id="link3"><!-- Elsie --></a>,
<a href="http://example.com/elsie" class="sister" id="link4"><!-- Elsie --></a>,
<a href="http://example.com/lacie" class="sister" id="link5">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link6">Tillie</a>;
and they lived at the bottom of a well.</p>
<p class="story xx">...2</p><p class="story">...3
<a class="as1">这是a1</a><a class="as1" id="a2">这是a2</a><a class="as1" href="http://59468.cn">这是a3</a>
</p>
"""


# 封装查找方法
def myFilter(tag):
    # 异常捕捉
    try:
        if tag.name == "p" and tag["class"] == ["story", "xx"]:
            return True
        return False
        # 多线程调用
    except Exception as err:
        print(err)


def print_hi_two():
    # 异常捕捉
    try:
        print("i2")
    except Exception as err:
        print(err)


# 清洗数据
def opO():
    try:
        soup = BeautifulSoup(dome, "html.parser")
        tags = soup.find_all(myFilter)
        print_hi_two()
        print(len(tags))
        print(tags)

    except Exception as e:
        print(e)


# 集体调用
def code():
    opO()
    print_hi_two()


if __name__ == '__main__':
    code()
